﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SubjectList.aspx.cs" Inherits="ZX.WebApp.EditWidows.SubjectList" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls.UserControl"
    TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/autocomplete/assets/skins/sam/autocomplete.css" />
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/autocomplete/autocomplete-min.js"></script>
    <script src="../Scripts/yui.list.button.event.js" type="text/javascript"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
    <script src="../Scripts/EasyUI/js/jquery-1.6.min.js" type="text/javascript"></script>
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <!-- 工具栏 -->
    <div id="listpage">
        <div id="toolbar">
            <div id="myAutoComplete" style="width: 100%; margin-top: 2px;">
                <button id="btnAddNew" type="button" style="width: 60px;
                    text-align: center">
                    新增</button>
                <button id="btnEdit" type="button" style="width: 60px;
                    text-align: center">
                    修改</button>
                <button id="btnDelete" type="button" style="width: 60px;
                    text-align: center">
                    删除</button>
                <button type="button" id="btnReload" name="btnReload" style="width: 60px;">
                    刷新</button>
                <button type="button" id="btnClose" name="btnClose" style="width: 60px;">
                    关闭</button>
                <button id="btnCheck" type="button" value="" onclick="fnCheck();" style="width: 80px;
                    text-align: center">
                    查看详情</button>&nbsp;&nbsp;
                <label for="lblIsFinish" id="lblIsFinish" style="padding-bottom:5px;">
                    是否完成:
                    <select id="SelectForState" onchange="ChangeState();">
                        <option value="Y" selected="selected">已完成</option>
                        <option value="N">未完成</option>
                    </select>&nbsp;&nbsp;
                </label>
                <label for="lblName" id="lblName">
                    接收人:
                    <input type="text" id="myInput" />
                    <input type="button" id="btnQuery" onclick="QueryData();" value="查询" style="width: 50px;
                        text-align: center" />
                </label>
                <label id="lblCustomer">
                    <%if (ShowCustomerType == "0" || ShowCustomerType == "2")
                      { %>
                        客户名
                    <% }else{ %>
                        决策人手机
                     <% } %>
                    为 <span style="color:Red;"> <%=CustomerName %> </span> 的客户信息已经存在!
                </label>
                <label id="lblCustomerName">
                    名称:
                    <input type="text" id="txtCustomerName" />
                    <input type="button" id="btnQueryCustomerName" onclick="QueryDataCustomerName();" value="查询" 
                            class="btnCheck" style="width: 50px; text-align: center" />
                </label>
            </div>
        </div>
        <div id="data">
            <div id="div2">
            </div>
            <div id="json">
            </div>
        </div>
        <div id="bottom">
            <div id="pagetotal" style="float: left; height: 25px; padding: 8px; margin-top: 3px;
                width: 100px;">
            </div>
            <div id="page" style="float: left">
            </div>
        </div>
    </div>
    <div id="dialog1" class="yui-pe-content">
        <div class="hd">
            选择题目</div>
        <div class="bd">
            <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    <div id="dialog2" class="yui-pe-content">
        <div class="hd">
            <% =PageTitles %> 数据编辑</div>
        <div class="bd">
            <iframe id="EditUIWindow2" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    <div id="dialog3" class="yui-pe-content">
        <div class="hd">
            提示</div>
        <div class="bd">
            你正在删除当前选择的数据，继续请按确定？
        </div>
    </div>
    </form>
</body>
<!--  用于加载自定义脚本 -->
<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
    var UserId = "<%=UserId %>";
    var const_entityID = "<% =EntityId %>",
        const_entityName = "<% =EntityName %>",
        const_EditEntity = "<% =EditEntity %>",
        const_condition = "<% =Condition %>",
        const_DataFields = [<% =DataFields %>],
        const_DataColums = [<% =DataColums %>],
        const_functionId   ="<% =FunctionID %>",//自定义条件
        const_Order ="<% =Order %>",           //排序 
        const_EditWindowWidth = "<% =EditWindowWidth %>px",
	    const_EditWindowHeight = "<% =EditWindowHeight %>px",
        const_PageTitle=encodeURI("<% =PageTitle %>"),
        selectControl=null,myDataTable="",requireUrl="",
        btnAddNew="",btnEdit="",btnDelete="",btnClose="",
        btnReload="",btnCheck="",btnQuery="",
        SaveUrl,dl,  //要删除的数据列
        const_customCondition= "<% =Condition %>";
    var questionnaireId = "<% =QuestinnaireId %>",subjectItems = "<%=SubjectItems %>",allItems = "<%=AllItems %>";
    var dutyId="<%=DutyId %>",customerValue="<%=CustomerName %>",customerType="<%=ShowCustomerType %>";
    var _PageTitle = parent._employeeTitle;

    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'top', body: 'toolbar', height: 35, gutter: '1px', maxHeight: 80 },
                { position: 'bottom',  height: 35, body: 'bottom', gutter: '1px', maxHeight: 130 },
                { position: 'center', body: 'data', gutter: '1px', scroll: true }
            ]});
            layout.render();
        });
    })();
    YAHOO.example.init = function () {
        function onButtonClick(p_oEvent) {
            switch (this.get("id")) {
                case "btnAddNew":
                    fnAdd();
                    break;
                case "btnEdit":
                    fnEdit();
                    break;
                case "btnDelete":
                    fnDelete();
                    break;
                case "btnReload":
                    LoadData();
                    break;
                case "btnClose":
                    fnClose();
                    break;
                default:
                    break;
            }
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
            btnAddNew = new YAHOO.widget.Button("btnAddNew");
            btnAddNew.on("click", onButtonClick);
            btnEdit = new YAHOO.widget.Button("btnEdit");
            btnEdit.on("click", onButtonClick);
            btnDelete = new YAHOO.widget.Button("btnDelete");
            btnDelete.on("click", onButtonClick);
            btnReload = new YAHOO.widget.Button("btnReload");
            btnReload.on("click", onButtonClick);
            btnClose = new YAHOO.widget.Button("btnClose");
            btnClose.on("click", onButtonClick);
            btnCheck = new YAHOO.widget.Button("btnCheck");
            btnCheck.on("click", onButtonClick);
            btnQuery = new YAHOO.widget.Button("btnQuery");
            btnQuery.on("click", onButtonClick);
            if(const_entityName=="V_TrSendQuestion"){
                document.getElementById("btnAddNew").style.display = "none";
                document.getElementById("btnEdit").style.display = "none";
                document.getElementById("btnDelete").style.display = "none";
                document.getElementById("btnReload").style.display = "none";
                document.getElementById("btnClose").style.display = "none";
                document.getElementById("lblCustomer").style.display = "none";
                document.getElementById("lblCustomerName").style.display = "none";
            }else if(const_entityName=="V_CrmCustomerShow"||const_entityName=="V_CrmCustomerInfoSale"){ //客户浏览功能
                document.getElementById("btnAddNew").style.display = "none";
                document.getElementById("btnEdit").style.display = "none";
                document.getElementById("btnDelete").style.display = "none";
                document.getElementById("btnReload").style.display = "none";
                document.getElementById("btnClose").style.display = "none";
                document.getElementById("btnCheck").style.display = "none";
                document.getElementById("lblIsFinish").style.display = "none";
                document.getElementById("lblName").style.display = "none";
                if(const_Order=="AddTime"){
                    document.getElementById("lblCustomer").style.display = "none";
                }else{
                    document.getElementById("lblCustomerName").style.display = "none";
                }
            }else{
                document.getElementById("btnCheck").style.display = "none";
                document.getElementById("lblIsFinish").style.display = "none";
                document.getElementById("lblName").style.display = "none";
                document.getElementById("lblCustomer").style.display = "none";
                document.getElementById("lblCustomerName").style.display = "none";
            }
        });
    } ();
    //新建
    var fnAdd = function(){
        if(const_entityName=="V_DatDutyType" || const_entityName=="V_DatDutyLevel"||const_entityName=="V_DatDutyGrade"){
            document.getElementById("EditUIWindow2").src = "../EditWidows/OrganizationalManager/AddDutyType.aspx?entity="+const_EditEntity+"&r=" + Math.random() + "";
            YAHOO.example.container.dialog2.show(); 
            return;
        }else if(const_entityName=="Set_DesktopItem"){
            document.getElementById("EditUIWindow2").src = "../Extend/AutoDTEditUI.aspx?r=" + Math.random() + "&entity=Set_DesktopItem"+"&RoleId="+getPar1("id");
            YAHOO.example.container.dialog2.show();
            SetDWH(450,200, YAHOO.example.container.dialog2);

        }
         else{
            if(parseInt(allItems) >= parseInt(subjectItems)){
                alert("问卷题目数已到达题目总数，不能再添加题目!");
            }else
            {
                document.getElementById("EditUIWindow2").src = "../TR/QuestionnaireSubject.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id="+ questionnaireId+"&its="+subjectItems;
                YAHOO.example.container.dialog2.show(); 
            }
        }
    }
    //编辑
    var fnEdit = function(){
        var recordID = mDataTable.getSelectedRows()[0];
        var records = mDataTable.getRecord(recordID);
        if(records != null){
            if(const_entityName=="V_DatDutyType" || const_entityName=="V_DatDutyLevel"||const_entityName=="V_DatDutyGrade"){
                document.getElementById("EditUIWindow2").src = "../EditWidows/OrganizationalManager/AddDutyType.aspx?entity="+const_EditEntity+"&r=" + Math.random() + "&id="+records.getData("PhraseID");
                YAHOO.example.container.dialog2.show(); 
                return;
            }
            else if(const_entityName=="Set_DesktopItem"){
                document.getElementById("EditUIWindow2").src = "../Extend/AutoDTEditUI.aspx?r=" + Math.random() + "&entity=Set_DesktopItem"+"&id="+records.getData("DesktopItemID")+"&RoleId="+getPar1("id");
                YAHOO.example.container.dialog2.show();
                SetDWH("450px","200px", YAHOO.example.container.dialog2);

            }
            else{
                document.getElementById("EditUIWindow2").src = "../TR/QuestionnaireSubjectEdit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id="+ records.getData("TrQuestionnaireSubjectID");
                YAHOO.example.container.dialog2.show();
                SetDWH(450,300, YAHOO.example.container.dialog2);
            }
        }else
        {
            alert("请选择一条记录!");
        }
    }
    //删除
    var fnDelete = function () {
        var list = this.mDataTable.getRecordSet()._records;
        var elist = [];
        dl = [];
        for (var i = 0; i < list.length; i++) {
            if (list[i]._oData["iSun_Selected"] == true) {
                elist.push(list[i]._oData[const_entityID]);
                dl.push(list[i]._sId); //获取行ID；
            }
        }
        if (elist.length == 0) {
            var recordID = myDataTable.getSelectedRows()[0];
            record = myDataTable.getRecord(recordID);
            if(record != null){
                if(const_entityName=="V_DatDutyType" || const_entityName=="V_DatDutyLevel" || const_entityName=="V_DatDutyGrade"){
                    SaveUrl = "../EditWidows/OrganizationalManager/DataProcessin.aspx?entity="+const_EditEntity+"&action=Delete&json="+record.getData(const_entityID);
                    YAHOO.example.container.dialog3.show();
                }
                else{
                    SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID);
                    YAHOO.example.container.dialog3.show();
                }
            }else{
                alert("请选择一条记录!");
            }
        }
        else {
            if(const_entityName=="V_DatDutyType" || const_entityName=="V_DatDutyLevel" || const_entityName=="V_DatDutyGrade"){
                SaveUrl = "../EditWidows/OrganizationalManager/DataProcessin.aspx?entity="+const_EditEntity+"&action=Delete&json="+record.getData(const_entityID);
                YAHOO.example.container.dialog3.show();
            }else{
                SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&json=" + elist.join(",");
                YAHOO.example.container.dialog3.show();
            }
        }      
    }
    //删除
    function DeleteData() {
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        alert("数据删除成功");
                        var recordID = mDataTable.getSelectedRows()[0];
                        if (dl.length == 0) {
                            mDataTable.deleteRow(recordID);
                        }
                        else {
                            for (var i = 0; i < dl.length; i++) {
                                mDataTable.deleteRow(dl[i]);
                            } 
                        }
                    }
                    else {
                        alert(str + "\n" + "数据删除失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
        YAHOO.example.container.dialog3.hide();
    }
 
    var getConst_condition=function(selectName){
        var obj=document.getElementById("myInput");
        if(obj.value!=""){
            var names = obj.value.split(",");
            var str = "";
            for (var i = 0; i < names.length; i++) {
                if (i != 0) {
                    str += " or ";
                }
                str += selectName + " like '%" + names[i] + "%' ";
            }
            return str;
        }
        else{
            return "";
        }
    }
    //预览
    var fnCheck = function(){
        debugger;
        var recordID = mDataTable.getSelectedRows()[0];
        record = mDataTable.getRecord(recordID);
        if (record == null) {
            alert("请选择一条记录");
            return;
        }
        var uid = record.getData("UserID");
        var url= "../TR/QSView.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&QID=" + record.getData(const_entityID)+"&uid="+uid;
        parent.document.getElementById("EditUIWindow3").src =url;
        parent.YAHOO.example.container.dialog5.show();
    }
    //网址列格式化
    var formatUrl = function (elCell, oRecord, oColumn, sData) {
        var v = oRecord.getData("CompanyNetting");
        if (v.indexOf("http") > -1) {
            elCell.innerHTML = "<a href='" + v+ "' target='_blank'>" + sData + "</a>";
        }
        else {
            elCell.innerHTML = "<a href='http://" + v + "' target='_blank'>" + sData + "</a>";
        }
    }

    var PageTotal;
    var pageindex = 1;
    var pagesize = 25;
    var ids="";
    var names="";
    var mDataTable;
    var CacheData=[];
    //刷新数据
    function LoadData(){
        BindData();
    }
     function ReLoadData(){
        BindData();
    }
    //数据绑定
    var myDataSource
    function BindData() {
        YAHOO.example.XHR_JSON = function() {
            var formatUrl = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
            };       
            var formatRating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = (sData === null) ? "N/A" : YAHOO.util.Number.format(sData);
            };
            var myColumnDefs = [
                    <% =DataFields %>
            ];
            myDataSource = new YAHOO.util.DataSource("../Extend/AjaxData/JSONList.aspx?");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            myDataSource.connXhrMode = "queueRequests";
            myDataSource.responseSchema = {
                resultsList: "rows",
                fields: [<% =DataColums %>]
            };
            
            if(const_entityName == "V_TrQuestionnaireSubject"){
                const_customCondition = encodeURI("TrQuestionnaireID='" + questionnaireId + "'");
            }else if(const_entityName == "V_TrSendQuestion"){
                var state=document.getElementById("SelectForState").value;
                var inputValue=document.getElementById("myInput").value;
                if(inputValue!=""){
                    const_customCondition="IsFinish='"+state+"' and " + encodeURI(getConst_condition("UName"));
                }
                else{
                    const_customCondition ="IsFinish='"+state+"'";
                }
                const_customCondition+=" AND "+ encodeURI("TrQuestionnaireID='" + questionnaireId + "'");
            }else if(const_entityName=="V_CrmCustomerShow"||const_entityName=="V_CrmCustomerInfoSale"){
                if(customerType=="0"){
                    const_customCondition = encodeURI("CustomerName='" + customerValue + "'");
                }else if(customerType=="1"){
                    const_customCondition = encodeURI("DecisionTel='" + customerValue + "'");
                }else if(customerType=="2"){
                    const_customCondition = encodeURI("DecisionTel2='" + customerValue + "'");
                }else if(customerType=="3"){
                    const_customCondition = encodeURI("CustomerName like '%" + customerValue + "%'");
                }
            }
            //------
            this.myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs,
                    myDataSource,{initialRequest: "pageindex="+pageindex+"&entity=" + const_entityName + "&r="+Math.random()+"&zip=94089&results=10&output=json"+"&condition="+const_condition+"&customCondition="+const_customCondition+"",selectionMode:"single"  },{ height:"100%"}  );
            //------
            mDataTable =this.myDataTable;
            var vurl = "pageindex="+pageindex+"&entity=" + const_entityName + "&r="+Math.random()+"&zip=94089&results=10&output=json"+"&condition="+const_condition+"&customCondition="+const_customCondition+"";
            
            GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + vurl);
            
            var mySuccessHandler = function() {
                this.set("sortedBy", null);
                this.onDataReturnAppendRows.apply(this,arguments);
            };
            var myFailureHandler = function() {
                    this.showTableMessage("没有数据", "没有数据");
                this.onDataReturnAppendRows.apply(this, arguments);
            };
            var callbackObj = {
                success : mySuccessHandler,
                failure : myFailureHandler,
                scope : myDataTable
            };
            mDataTable = this.myDataTable;
            //调用自定义双击行的方法
            parent._CustomerId="";
            var dbClick= function(){
                var recordID =mDataTable.getSelectedRows()[0];
                record = mDataTable.getRecord(recordID);
                var id = record.getData("ID");
                parent._CustomerId=id;
            }
	        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
	        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
            this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow); 
            this.myDataTable.subscribe("rowClickEvent", dbClick); 
            this.myDataTable.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
            });
            this.myDataTable.selectRow(this.myDataTable.getTrEl(0)); 
            hideCol();
        }();
    }
    //隐藏/栏位
    function hideCol(){ 
        mDataTable.hideColumn(parseInt(0)); mDataTable.refreshView();
    };
    YAHOO.util.Event.addListener(window, "load", LoadData);
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {  
	    var handleCancel = function() {
		    this.cancel();
	    };
        var handleSuccess1 = function(o) {
		    var editwindow = document.getElementById("EditUIWindow1");
            if(editwindow)
            {
                editwindow.contentWindow.Save();
            }
	    };
	    var handleSuccess2 = function(o) {
		    var editwindow = document.getElementById("EditUIWindow2");
            if(editwindow)
            {
                editwindow.contentWindow.Save();
            }
	    };
	    var handleFailure = function(o) {
		    alert("Submission failed: " + o.status);
	    };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
							    { width: "550px",
							        height: "350px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: handleSuccess1, isDefault: true },
								            { text: "取消", handler: handleCancel}]
							    });
        YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
							    { width: "550px",
							        height: "350px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: handleSuccess2, isDefault: true },
								            { text: "取消", handler: handleCancel}]
							    });
        YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3",
							    { width: "350px",
							        height: "90px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: DeleteData, isDefault: true },
								            { text: "取消", handler: handleCancel}]
							    });
        YAHOO.example.container.dialog1.render();
        YAHOO.example.container.dialog2.render();
        YAHOO.example.container.dialog3.render();
    });
    var ChangeState=function(){   
        LoadData(); 
    } 
    var QueryData = function(){ 
        LoadData();
    }
    var QueryDataCustomerName = function(){
        switch(const_entityName)
        {
            case "V_CrmCustomerShow":
            case "V_CrmCustomerInfoSale":
                const_condition=encodeURI(getConst_condition("CustomerName"));
            break;
        }
        const_customCondition="";
        LoadData();
    }
    var getConst_condition=function(selectName){
      var obj=document.getElementById("txtCustomerName");
      if(obj.value!=""){
          var names = obj.value.split(",");
              var str = "";
            var selectNames=selectName.split(',');
            for(var j=0;j<selectNames.length;j++){
                for (var i = 0; i < names.length; i++) {
                    if (i != 0) {
                        str += " or ";
                    }
                    str += selectNames[j] + " like '%" +names[i] + "%' ";
                }
            }
            return str;
       }
       else{
         return "";
       }
   }
    // 用于数据刷新
    YAHOO.widget.DataTable.prototype.requery = function (newRequest) {
         myDataSource.liveData = "../Extend/AjaxData/JSONList.aspx?"+newRequest;
         mDataTable.getDataSource().sendRequest(null,
            {success: mDataTable.onDataReturnInitializeTable},
            mDataTable)
    };
    //关闭窗口
    function closeWin(type){
        if(type == 1){
            YAHOO.example.container.dialog1.hide();
        }
        if(type == 2){
            YAHOO.example.container.dialog2.hide();
        }
        LoadData();
    }
      function closeWin(){
        YAHOO.example.container.dialog2.hide();
    }
    //退出
    function fnClose(){
        try
        {
            window.parent.$("#tabs").tabs('close',_PageTitle);
        }catch(e){
            parent.YAHOO.example.container.dialog2.hide();
        }
    }

    // 获取最新的总数
    var GetTotal = function (url) {
        YAHOO.util.Connect.asyncRequest('POST', url, {
            success: function (res) {
                var o = eval(res.responseText);
                SetPaging(o[0].total);
                if (document.getElementById("pagetotal") != null) {
                    document.getElementById("pagetotal").innerHTML = "<b>共<font color=\"red\">" + o[0].total + "</font>笔记录</b>";
                }
            },
            failure: function (error) {
            }
        }, null);
    }
    //--分页使用
    //GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + initialRequestUrl);

    // 分页方法
    var SetPaging = function (total) {
        var Ex = YAHOO.namespace('example');
        Ex.handlePagination = function (state) {
            pageindex = state.page;
            pagesize = Ex.Config.rowsPerPage;
            var requestStr = "pagesize=" + Ex.Config.rowsPerPage + "&pageindex=" + pageindex + "&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + const_customCondition + "&condition=" + const_condition;
            myDataTable.requery(requestStr);
            Ex.paginator.setState(state);
        };
        Ex.Config = {
            rowsPerPage: 25,
            firstPageLinkLabel: "第一页",
            lastPageLinkLabel: "尾页",
            previousPageLinkLabel: "上一页",
            nextPageLinkLabel: "下一页",
            totalRecords: total,
            containers: 'page'
        };
        Ex.paginator = new YAHOO.widget.Paginator(Ex.Config);
        Ex.paginator.subscribe('changeRequest', Ex.handlePagination);
        Ex.paginator.render();
    }
    // 设置对话框的大小
    var SetDWH = function (width, height, dialog) {
        var  elements = YAHOO.util.Dom.getElementsByClassName('bd', 'div')[0];
        var w = [],
            h = [];
        w.push(width);
        h.push(height);
        dialog.configWidth(null, w);
        dialog.configHeight(null, h);
        dialog.render();
        if(elements){
            dialog.fillHeight(elements);
        }
    }
    // 设窗口最大化
    var SetMaxDWH = function (dialog) {
        var w = Y.util.Dom.getViewportWidth() - 20;
        var h = Y.util.Dom.getViewportHeight() - 20;
        SetDWH(w, h, dialog);
    }
</script>
</html>
